#ifndef __GAF_EFFECT_H__
#define __GAF_EFFECT_H__

#include "GAF_Define.h"

namespace GAF
{
	//class Player
		//class Animation -* Runnble
	//class Graphics -* ForEach
			class Effect;
}
typedef GAF::Effect			GAF_CEffect;

#include "GAF_Graphics.h"
#include "GAF_Player.h"
#include "GAF_Package.h"

#define GAF_EFFECT_START_ID		0
#define GAF_EFFECT_END_ID		-1

#define GAF_PRM_EFFECT_START_i		"EffectStart"
#define GAF_PRM_EFFECT_END_i		"EffectEnd"
#define GAF_PRM_EFFECT_LOOP_b		"EffectLoop"
#define GAF_PRM_EFFECT_REVERSE_b	"EffectReverse"

namespace GAF
{
	/// 特效类
	class _ABSTRACT Effect : public Graphics, public Player
 	{
	private:
		enum ResKind
		{
			RES_UNKNOW,
			RES_PACKAGE,
			RES_IMAGE
		};

	public:
		Effect();
		virtual ~Effect();

	public:
		DIM_ATTRIB(int, Step);
		DIM_ATTRIB(bool, Reverse);
		DIM_ATTRIB_ASSOCIATED_R(int, Frame, m_nCurFm);

	public:
		/// 初始化
		bool			Init(Bundle* pbdlParam = NULL);
		/// 初始化
		bool			Init(Package* pPackage, const UINT nStartID = GAF_EFFECT_START_ID, const int nEndID = GAF_EFFECT_END_ID, Bundle* pbdlParam = NULL);
		/// 初始化
		bool			Init(Image* pImage, const UINT nWidthNum, const UINT nHeightNum, const UINT nFrameNum, Bundle* pbdlParam = NULL);

	protected:
		virtual	bool		OnInit(GAF_CBundle* pbdlParam)
					{return true;}

	public:
		/// 播放到指定帧
		void			PlayTo(UINT nToFrame);
		/// 播放自由控制
		void			PlayFree(UINT nStartFrame, UINT nEndFrame, bool isLoop = false, bool isReverse = false);

		/// 重置
		bool			Reset(Package* pPackage, const UINT nStartID = GAF_EFFECT_START_ID, const int nEndID = GAF_EFFECT_END_ID);
		/// 重置
		bool			Reset(Image* pImage, const UINT nWidthNum, const UINT nHeightNum, const UINT nFrameNum);

		/// 获得当前开始帧
		UINT			GetStartFrame();
		/// 获得当前结束帧
		UINT			GetEndFrame();
		/// 获取当前可播放帧数
		UINT			GetFrameCount();
		/// 获取所有帧数
		UINT			GetAllFrameCount();
		/// 设置当前帧
		void			SetFrame(UINT nFrameID);

		void			AddStep();

		/// 获得当前帧图像句柄
		ImageHandle		GetFrameImageHandle();
		/// 获得当前帧图像矩形
		Rect			GetClip_a();

	private:
		int			GetUpdateFrame(TimeTicks ttUsed);
		void			LoadPkgFrame(UINT nID);

// 继承
 		// 定义操作
 	protected:
 		// 播放操作
 		bool			Playing(Bundle* pbdlParam);
 		// 运行操作
 		bool			Running(TimeTicks ttUsed, bool& isFinish);
// 		// 暂停操作
// 		virtual bool		Pauseing()
// 					{return true;}
// 		// 完成操作
// 		virtual bool		Finishing()
// 					{return true;}
// 		// 停止操作
// 		virtual bool		Stopping()
// 					{return true;}

// 		// 定义事件
// 	protected:
// 		// 当播放时
// 		virtual bool		OnPlay(GAF_CBundle* pbdlParam)
// 					{return true;}
// 		// 当播放更新时
// 		virtual bool		OnUpdate(TimeTicks ttUsed)
// 					{return true;}
// 		// 当播放暂停时
// 		virtual bool		OnPause()
// 					{return true;}
// 		// 当完成一次播放时
// 		virtual bool		OnFinish()
// 					{return true;}
// 		// 当播放停止时
// 		virtual bool		OnStop()
// 					{return true;}

	private:
		ResKind			m_ERK;
		ImageHandle		m_hFrame;
		Rect*			m_rClips;

		// ERK_Package
		Package*		m_pPackage;
		// ERK_Image
		ImageHandle		m_hImage;

	private:
		Bundle			m_Param;		// 播放传递参数

		int			m_nStartID;		// 动画开始位置
		int			m_nEndID;		// 动画结束位置

		int			m_nStartFm;		// 播放开始帧
		int			m_nEndFm;		// 播放结束帧
		int			m_nCurFm;		// 播放当前帧

		TimeTicks		m_ttExtra;		// 多余的更新时间
 	};
}

#endif
